#### Overview
## For each inventory: read in data, keep only the question columns,
## change all 0 responses to NA, and keep only rows that have no NA's,
## call 'scaleTester' function on each cleaned inventory.
## All fixed_scale columns were cross-referenced with the text of the
## questions listed in each cited article and the text listed in the codebook

rm(list = ls())
setwd("~/Application1/SimulationCode")
source("scaleTester.R")
num_cores = 2


## Narcissistic Inventory ----------------------------------------------------
narc_data <- read.csv("../Data/NPI/data.csv")
narc_cols <- paste("Q", c(1:40), sep = "")
narc_data <- narc_data[ , narc_cols]
narc_data[narc_data == 0] <- NA
narc_data <- narc_data[complete.cases(narc_data), ]

response_rate(battery = read.csv("../Data/NPI/data.csv"), narc_cols)

fixed_scale <- c(4, 7, 9, 12, 13, 14, 20, 21, 23, 24, 30, 32, 34, 35, 39, 40)
fixed_scale <- paste("Q", fixed_scale, sep = "")

scaleTester(do_install = FALSE,
            full_data = narc_data,
            num_questions = 16,
            num_cores = num_cores,
            out_stub = "../SimulationOutput/Narc.R",
            fixed_scale = fixed_scale)

## Machivallianism Inventory -------------------------------------------------
mach_data <- read.csv("../Data/MACH2/data.csv")
mach_cols <- paste("Q", 1:20, sep = "")
mach_data <- mach_data[ , mach_cols]
mach_data[mach_data == 0] <- NA
mach_data <- mach_data[complete.cases(mach_data), ]

response_rate(battery = read.csv("../Data/MACH2/data.csv"), mach_cols)

fixed_scale <- c(1, 5, 12, 13, 4)
fixed_scale <- paste("Q", fixed_scale, sep = "")

scaleTester(do_install = FALSE,
            full_data = mach_data,
            num_questions = 5,
            num_cores = num_cores,
            out_stub = "../SimulationOutput/Mach.R",
            fixed_scale = fixed_scale)

## Empathazing Inventory -----------------------------------------------------
EQSQ_data = read.table("../Data/EQSQ/data.csv", header = TRUE)
emp_cols <- c(1:60)[-c(2, 3, 5, 7, 9, 13, 16, 17, 20, 23, 24, 28, 30,
                           33, 40, 45, 47, 51, 53, 56)]
emp_data <- EQSQ_data[ , paste("E", emp_cols, sep = "")]
emp_data[emp_data == 0] <- NA
emp_data <- emp_data[complete.cases(emp_data), ]

response_rate(battery = read.table("../Data/EQSQ/data.csv", header = TRUE),
              these_cols = paste("E", emp_cols, sep = ""))

fixed_scale <- c(25, 26, 44, 52, 54, 4, 8, 12, 14, 35, 6, 27, 32, 50, 59)
fixed_scale <- paste("E", fixed_scale, sep = "")

scaleTester(do_install = FALSE,
            full_data = emp_data,
            num_questions = 15,
            num_cores = num_cores,
            out_stub = "../SimulationOutput/Emp.R",
            fixed_scale = fixed_scale)

## Systemizing Inventory -----------------------------------------------------
syst_cols <- c(1:60)[-c(2, 3, 8, 9, 10, 14, 16, 17, 21, 22, 27, 36,
                        39, 46, 47, 50, 52, 54, 58, 59)]
syst_data <- EQSQ_data[ , paste("S", syst_cols, sep= "")]
syst_data[syst_data == 0] <- NA
syst_data <- syst_data[complete.cases(syst_data), ]

response_rate(battery = read.table("../Data/EQSQ/data.csv", header = TRUE),
              these_cols = paste("S", syst_cols, sep = ""))

fixed_scale <- c(5, 7, 11, 12, 13, 15, 18, 20, 24, 26, 31, 32, 33, 34, 35,
                 37, 40, 41, 43, 45, 48, 49, 51, 55, 57)
fixed_scale <- paste("S", fixed_scale, sep = "")

scaleTester(do_install = FALSE,
            full_data = syst_data,
            num_questions = 25,
            num_cores = num_cores,
            out_stub = "../SimulationOutput/Syst.R",
            fixed_scale = fixed_scale)



